﻿using System.Windows;
using System.Windows.Controls;
using Apps.Yunwei.ViewModels;
using QDP.Platform.Silverlight;
using Services.Works;
namespace Apps.Yunwei
{
    public partial class UsersWidget : UserControl,IWorkView
    {
        public UsersWidget()
        {
            InitializeComponent();
            this.Loaded += UsersWidget_Loaded;
        }

        void UsersWidget_Loaded(object sender, RoutedEventArgs e)
        {
            viewModel = (this.DataContext as UsersViewModel);
            viewModel.SetConfig(this.GetConfigs());
        }
        UsersViewModel viewModel = null;
        public object ToDo(params object[] args)
        {
            string type = args.Length >= 1 ? args[0].ToString() : string.Empty;
            string id = args.Length >= 2 ? args[1] == null ? string.Empty : args[1].ToString() : string.Empty;
            switch (type)
            {
                case "add":
                    viewModel.AddContact();
                    break;
                case "edit":
                    foreach (var user in viewModel.Items)
                    {
                        if (user.Code == id) { viewModel.EditContact(user); break; }
                    }
                    break;
                default:
                    break;
            }
            return null;
        }
    }
}
